﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO.Ports;
using System.Data;
using System.Data.SqlClient;

namespace weiqijiance.控制流程
{
    public class flowcrtl
    {
        public string sjcbz ;//检测标准
        public static int iquanjuzhuangtai = 0;//尾气与车速，动力性状态
        public string photosIP;
        public int photosPort;//cjm
        public bool bzhgw = false;//是否最后一个工位
        public string gwjysbbh = "";//设备编号 昂特公司用于设置检测点的 暂时还没设置
        public string gwjysbbhzbzl = "";//设备编号 昂特公司用于设置检测点的 暂时还没设置
        public string gwjysbbhwkcc = "";//设备编号 昂特公司用于设置检测点的 暂时还没设置
        public string gwjysbbhzc = "";//设备编号 昂特公司用于设置检测点的 暂时还没设置
        public int sqz = 0;
        public string ssfAJLW = "否";
        public string ssfAJLWmoto = "否";
        public string lwpt = "全国联网平台";
        public string sweburl="";
        public string sjcz="";
        public string ssqm="";
        public string ssqqzr="";
        public int isptongdao=-1;
        public int iaptongdao=-1;
        public int ilitongdao=-1;
        public int ilitongdao2 = -1;
        public int isltongdao=-1;
        public int ibrtongdao=-1;
        public int ibrtongdao2=-1;
        public int ibrtongdaojz = -1;
        public int ibrtongdaozc = -1;
        public int izbzlqtongdao = -1;
        public int izbzlhtongdao = -1;
        public int iwkccqtongdao = -1;
        public int iwkccthongdao = -1;
        public int idlxtongdao=-1;
        public int idpjxytongdao = -1;
        public int ilzgwtongdao = -1;
        public int ipbzdqtongdao = -1;
        public int ipbzdhtongdao = -1;
        public string ledfactory = "维柯";
        public string ledpinghao = "1";
        public 灯牌.ledbass ledctrl = new 灯牌.ledbass();
        public SerialPort dpcomm = new SerialPort();
        public SerialPort dpcommwkcc = new SerialPort();
        public string sdpcomm;
        public string sdpcommwkcc;
        public mainform m_mainform;
        public string sshebei = "";
        public string sgongwei = "";
        public string jylsh = "";
        public string sDetectID = "";
        public int izhuangtai = 0;//0:空闲 1:忙碌 2:启用 3:下线
        public string ok;
        public bool bStandard = false;//视频时间已经达标
        public string reportzc = "";//记录驻车
        public string ddgxh = "1";
        public string web = "";
        public int m_iycyzl = 0;

        public bool IsCancle()
        {
            if (izhuangtai == 3)
            {
                return true;
            }
            return false;
        }
        public void initajlw()
        {
            if (lwpt.Contains("全国联网平台"))
            {
                objajlwbass = new 安检联网.ajlwbass();
            }
            if (lwpt.Contains("昂特"))
            {
                if (sjcbz.Contains("38900"))
                {
                    objajlwbass = new 安检联网.angteclass38900();
                }
                else
                {
                    objajlwbass = new 安检联网.angteclass();
                }
            }
            if (lwpt.Contains("贵阳睿擎"))
            {
                if (sjcbz.Contains("38900"))
                {
                    objajlwbass = new 安检联网.ruiqing38900();
                }
                else
                {
                    objajlwbass = new 安检联网.ruiqingclass();
                }
            }
            if (lwpt.Contains("梅州"))
            {
                objajlwbass = new 安检联网.meizhouclass();
            }
            if (lwpt.Contains("全国") && sjcbz.Contains("38900"))
            {
                objajlwbass = new 安检联网.quanguo38900();
            }
            if (lwpt.Contains("海口") )
            {
                objajlwbass = new 安检联网.lianwang_海口();
            }

            objajlwbass.m_mainform = m_mainform;
            objajlwbass.sweb = sweburl;
            objajlwbass.jyjgbh = sjcz;
            objajlwbass.ssqm = ssqm;
            objajlwbass.ssqqzr = ssqqzr;
            objajlwbass.ssfAJLW = ssfAJLW;
            objajlwbass.photosIP = photosIP;
            objajlwbass.photosPort = photosPort;
        }

        public string start = "";
        public void sendend(string sbz, string jylsh)
        {
            m_mainform.bpanelshow = false;
            m_mainform.showpanel();
            m_mainform.objsocket.send(string.Format("{0},{1},{2},{3}{4},{5}", sbz, jylsh, sshebei, sshebei, "结束", sbz));
        }
       
        public int m_iDetectID = -1;
        public string sYCY;
        public string sDPCZY;
        public string sPlate = "";
        public string sPclass="";
        public string svin;
        public bool bnj;
        public bool bzj;
        public bool bsj;
        public bool blj;//临时检验抓拍
        public int izs;
        public int iVax;
        public int iCLZZL = 0;
        public int iCLZWS = 0;
        public bool bSmallVeh = false;
        //---------------------------------
        public string absType = "1"; //车辆 整备质量
        public int iCLZBZL = 0; //车辆 整备质量
        public DateTime dCCRQ;////LOGINRECORD 表中要增加LR_DMADE制造日期
        public int iEDZS = 0;//dt.Rows[0]["LR_REV"].ToString().Trim();//额定转速
        public string sqzdz;
        public int iQZDZ;//=sqzdz.Find("二",0)>-1 ? 2:4;//dt.Rows[0]["AT_LAMP"].ToString().Trim();//灯制
        public bool bNewFlag;//=sdj.Find("注册")>-1 ? TRUE:FALSE;//看检测类别 dt.Rows[0]["LR_NEWFLAG"].ToString().Trim();//新车标志
        public int iITERAT;//=dt.Rows[0]["DET_ITERAT"].ToString().Trim();//检测次数 
        public bool bJCWJ;//= dt.Rows[0]["DET_APPEAR"].ToString().Trim();//外检
        public bool bJCDG;// = dt.Rows[0]["DET_CHASSIS"].ToString().Trim();//底盘
        public bool bJCDPDT;//= dt.Rows[0]["DET_DYNA"].ToString().Trim();//底盘动态
        public bool bJCCSB;//= dt.Rows[0]["DET_SPEED"].ToString().Trim();//车速
        public bool bJCZZD;//= dt.Rows[0]["DET_LEDML"].ToString().Trim();//灯光
        public bool bJCYZD;//= dt.Rows[0]["DET_LEDMR"].ToString().Trim();
        public bool bJCZFD;//= dt.Rows[0]["DET_LEDAL"].ToString().Trim();
        public bool bJCYFD;//= dt.Rows[0]["DET_LEDAR"].ToString().Trim();
        //public  int iQZDZ = 2;
        public bool bJCCH;//=dt.Rows[0]["DET_SLIP"].ToString().Trim();//侧滑
        public bool bJCZBZL;//=dt.Rows[0]["DET_SLIP"].ToString().Trim();//整备质量
        public bool bJCWKCC;//=dt.Rows[0]["DET_SLIP"].ToString().Trim();//外廓尺寸
        //public  bool bJCXCZD;//=FALSE;
        public bool[] bJCXCZDZ = new bool[6];
        public bool bJCXCZD = false;
        public bool[] bJCJZZDZ = new bool[6];
        public bool[] bJCZCZDZ = new bool[6];
        public bool bJCZCZD = false;
        public bool bFYYWXX=false;//=dt.Rows[0]["DET_YJGPY"].ToString().Trim();//  是否评价灯光偏移 真为不评价
        public bool bqzd;// = (dt.Rows[0]["AT_QZD"].ToString().Trim());
        public bool bGC;
        public float fmubiaosudu = 0;
        public float STD_YOUHAO = 0;
        public float iqdzbzl = 0;
        public float fyhfr = 0;
        public bool bJCGL = false;
        public bool bJCXJ = false;
        public bool bJCJSSJ = false;
        public bool bQLSZX = false;
        public string sCllx = "";
        public bool bJCSJ = false;
        public float fgonglv = 0;
        public float fhdzs = 0;
        public float fhdnj = 0;
        public string sfuel = "";
        public bool bSLTJ = false;
        public model.安检联网.carclass objcarclass = new model.安检联网.carclass();
        public 安检联网.ajlwbass objajlwbass = new 安检联网.ajlwbass();
        public string sxcrh = "";
        public int ichang = 0;
        public int ikuan = 0;
        public int igao = 0;
        public int ihxc = 0;
        public int ihxk = 0;
        public int ihxg = 0;
        public string scsys = "";
        public string owner = "";
        public string szhouju = "";
        public string szczw = "";
        public bool ifinish=false;//记录是否已经发送总结束,开始业务写入是false,如果已经工位发送总结束,平台会更新位true,仪表读取到位true，就不发送总结束
        public bool bweight = false;
        public int wbzl;
        public string lbgd="";
        public string sZCHPHM = "";

        //-------------------------------
        public bool IsReadyForStart()
        {
            szhouju = "";
            scsys = "";
            sxcrh = "";
            bnj = false;
            bzj = false;
            bFYYWXX = false;
            blj = false;
            int.TryParse(sDetectID, out m_iDetectID); ;
           
            string iAT_ID = "0";
            string sSQLCmd;
            sSQLCmd = string.Format(@"SELECT * from AUTO,Detects_SJA where AUTO.AT_ID=Detects_SJA.AT_ID and Detects_SJA.DETECT_ID={0}", m_iDetectID);
            DataTable dt = m_mainform.objdbbass.GetTable(sSQLCmd);
            if (dt.Rows.Count > 0)
            {
                m_iycyzl = getycyzl(dt.Rows[0]["DET_YCY"].ToString().Trim());

                int.TryParse(dt.Rows[0]["AT_WBZL"].ToString().Trim(), out wbzl);
                lbgd = dt.Rows[0]["AT_LBGD"].ToString().Trim();
                iAT_ID = dt.Rows[0]["AT_ID"].ToString().Trim();
                sYCY = dt.Rows[0]["DET_YCY"].ToString().Trim().Length>0?dt.Rows[0]["DET_YCY"].ToString().Trim():"test";//引车员
                sDPCZY = dt.Rows[0]["DET_DPCZY"].ToString().Trim().Length > 0 ? dt.Rows[0]["DET_DPCZY"].ToString().Trim() : "test";//引车员
                ok = ((dt.Rows[0]["DET_JYZJL"].ToString().Trim().Contains("1")) ? 1 : 0).ToString();
                jylsh = dt.Rows[0]["DET_LSH"].ToString().Trim();
                sPlate = dt.Rows[0]["AT_HPHM"].ToString().Trim(); //检测车牌
                svin = dt.Rows[0]["AT_VIN"].ToString().Trim(); //车架号
                sPclass = dt.Rows[0]["AT_HPZL"].ToString().Trim(); //号牌种类
                scsys = dt.Rows[0]["AT_CSYS"].ToString().Trim(); //
                owner = dt.Rows[0]["AT_SYR"].ToString().Trim(); //
                szhouju = dt.Rows[0]["AT_ZJ"].ToString().Trim(); //
                string sdj = dt.Rows[0]["DET_JCLB"].ToString().Trim();//LR_INSPECT
                szczw = dt.Rows[0]["AT_ZCZW"].ToString().Trim(); //
                sZCHPHM = dt.Rows[0]["AT_ZCHPHM"].ToString().Trim(); //

                try
                {
                    ifinish = (bool)dt.Rows[0]["DET_FINISH"]; //
                }
                catch
                {
                    ifinish = false;
                }

                try
                {
                    bweight = (bool)dt.Rows[0]["DET_BWEIGHT"]; //
                }
                catch
                {
                    bweight = false;
                }

                //bweight = (bool)dt.Rows[0]["DET_BWEIGHT"]; //
                sxcrh = sdj;//.Contains("注册")?"00":"01";

                string sdj2 = dt.Rows[0]["DET_JCLB"].ToString().Trim();//LR_INSPECT
                blj = true;
                bzj = false;
                bsj = false;
                bnj = false;

                sCllx = dt.Rows[0]["AT_CLLX"].ToString().Trim();//车辆类型

               
                izs = 1;
               
               
                int.TryParse(dt.Rows[0]["AT_ZS"].ToString().Trim(), out iVax);

                sqz = 1;

               int.TryParse(dt.Rows[0]["AT_ZZL"].ToString().Trim(), out iCLZZL); ///*总质量*/

                int.TryParse(dt.Rows[0]["AT_ZBZL"].ToString().Trim(), out iCLZBZL); //车辆 整备质量

                int.TryParse(dt.Rows[0]["AT_CHANG"].ToString().Trim(), out ichang);
                int.TryParse(dt.Rows[0]["AT_KUAN"].ToString().Trim(), out ikuan);
                int.TryParse(dt.Rows[0]["AT_GAO"].ToString().Trim(), out igao);

                int.TryParse(dt.Rows[0]["AT_HXCHANG"].ToString().Trim(), out ihxc);
                int.TryParse(dt.Rows[0]["AT_HXKUAN"].ToString().Trim(), out ihxk);
                int.TryParse(dt.Rows[0]["AT_HXGAO"].ToString().Trim(), out ihxg);
                GetABS(dt.Rows[0]["AT_OBD"].ToString().Trim());



                bool.TryParse(dt.Rows[0]["DET_BSLTJ"].ToString().Trim(), out bSLTJ); //四轮同检标志

                iEDZS = 0;//

                ////////////////////////////////////////////////////
                string sqzdz = dt.Rows[0]["AT_LAMP"].ToString().Trim();
                if (sqzdz.Contains("一"))
                {
                    iQZDZ = 1;
                }
                else if (sqzdz.Contains("二"))
                {
                    iQZDZ = 2;
                }
                else
                {
                    iQZDZ = 4;
                }

                var sjyxm = "";
                sjyxm = dt.Rows[0]["DET_BJYXM"].ToString().Trim();

                int.TryParse(dt.Rows[0]["DET_JYCS"].ToString().Trim(), out iITERAT);//检测次数 
                if (sjyxm.Contains("C1"))
                {
                    bJCDG = true;
                }
                else
                {
                    bJCDG = false;
                }

                if (sjyxm.Contains("S1"))
                {
                    bJCCSB = true;
                }
                else
                {
                    bJCCSB = false;
                }


                 if (sjyxm.Contains("A1"))
                 {
                     bJCCH = true;
                 }
                 else
                 {
                     bJCCH = false;
                 }

                 if (sjyxm.Contains("SJ"))
                 {
                     bJCSJ = true;
                 }
                 else
                 {
                     bJCSJ = false;
                 }


                 if (sjyxm.Contains("H1"))
                 {
                     bJCZZD = true;
                 }
                 else
                 {
                     bJCZZD = false;
                 }
                 if (sjyxm.Contains("H4"))
                 {
                     bJCYZD = true;
                 }
                 else
                 {
                     bJCYZD = false;
                 }

                bJCXCZD = false;
                for (int k = 0; k < 5; k++)
                {
                    if (sjyxm.Contains(string.Format("B{0}",k+1)))
                    {
                        bJCXCZDZ[k] = true;
                    }
                    else
                    {
                        bJCXCZDZ[k] = false;
                    }
                }

                if (sjyxm.Contains("B0"))
                {
                    bJCZCZDZ[1] = true;
                }


                float.TryParse(dt.Rows[0]["AT_GL"].ToString().Trim(), out fgonglv);
                float.TryParse(dt.Rows[0]["AT_FDJZS"].ToString().Trim(), out fhdzs);
                float.TryParse(dt.Rows[0]["AT_NJ"].ToString().Trim(), out fhdnj);


                sfuel = dt.Rows[0]["AT_RYZL"].ToString().Trim();
                float.TryParse(dt.Rows[0]["AT_YHXZ"].ToString().Trim(), out STD_YOUHAO);

                objcarclass.jylsh = jylsh;
                objcarclass.jycs = (iITERAT).ToString();
                objcarclass.hphm = sPlate;
                objcarclass.hpzl = sPclass;
                objcarclass.clsbdh = svin;
                objcarclass.jcxdh =m_mainform.jcxdh;//检测线编号
                objcarclass.jyjgbh = m_mainform.sjcz;//检测站编号
                objcarclass.sjylb = sdj2;//检验类别

                GetStand(iAT_ID);

            }
            else
            {
                return false;
            }

            return true;

        }

        //上下偏移
        public float STD_LFVU = 0;
        public float STD_LFVB = 0;
        public float STD_LNVU = 0;
        public float STD_LNVB = 0;

        //水平偏移
        public float STD_LFLHB = 0;
        public float STD_LFLHU = 0;
        public float STD_LFRH = 0;
        public float STD_LFRH1 = 0;
        public float STD_LFRH2 = 0;
        public float STD_LFRH3 = 0;
        //////////远光

        public int STD_LI = 0;
        public int STD_BRIGHTEF = 0;//225000;//光强和 wwt20120731 7258 2012
        //制动
        public float STD_FBRAKEDIF = 0;
        public float STD_BBRAKEDIF1 = 0;
        public float STD_BBRAKEDIF2 = 0;//%8
        public float STD_BRAKE1 = 60;//60%//拐点
        //制动不平衡率ZJ
        public float STD_BPLPJ1 = 0;
        public float STD_BPLPJ2 = 0;
        public float STD_BPLPJ2GD = 0;
        public float STD_zdl = 0;
        /////////////////////////////////////////////////
        public float STD_BRAKE3 = 0;
        public float STD_BRAKE2 = 0;/*20%小车后轴*/
        public float STD_FBRAKE = 0;/*前轴60%*/
        //喇叭
        public float STD_BRAKEF = 0;//整车
        ///////////////////////////////////////////////////////////////////////////////
        public float STD_HALT = 0;
        public float STD_JZZDL = 0;
        public float STD_SLIPH = 0;//侧滑
        public float STD_SLIPL = 0;
        public float STD_SPDOLO = 0;//车速
        public float STD_SPDOHI = 0;

        bool GetStand(string iat_id)//21861
        {//取检测标准

            //取检测标准

            string sSQLCmd;
            sSQLCmd = string.Format("Select * from STAND_XZ Where AT_ID={0}", iat_id);
            DataTable dt = m_mainform.objdbbass.GetTable(sSQLCmd);
            if (dt.Rows.Count > 0)
            {

                STD_SLIPH = (float)dt.Rows[0]["XZ_SLIPH"];//侧滑
                STD_SLIPL = (float)dt.Rows[0]["XZ_SLIPL"];

                STD_SPDOLO = (float)dt.Rows[0]["XZ_SPDOLO"];//车速
                STD_SPDOHI = (float)dt.Rows[0]["XZ_SPDOHI"];

            }
            return true;
        }

        Class_DES des = new Class_DES();
        public float[] VAX_WEIGHT = new float[5];
        public float[] VAX_WEIGHTZC = new float[5];
        public float[] VAX_VBRAKEL = new float[5];
        public float[] VAX_VBRAKER = new float[5];
        public float[] VAX_VWGHTL = new float[5];
        public float[] VAX_VWGHTR = new float[5];
        public float[] VAX_VPARKEL = new float[5];
        public float[] VAX_VPARKER = new float[5];
        public float[] VAX_VWGHTLSP = new float[5];
        public float[] VAX_VWGHTRSP = new float[5];
        public void getlunzhong()
        {
            string sSQLCmd;

          
            sSQLCmd = string.Format("Select * From Detects_SJB Where DETECT_ID={0}", sDetectID);
            DataTable dt = m_mainform.objdbbass.GetTable(sSQLCmd);
            if (dt.Rows.Count > 0)
            {
                for (int iPos = 0; iPos < 5; iPos++)
                {
                    int i = iPos + 1;
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTH{0}", i)].ToString().Trim()), out VAX_WEIGHT[iPos]);        //轴重VAX_WEIGHT
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_BRAKEL{0}", i)].ToString().Trim()), out VAX_VBRAKEL[iPos]);       //左制动力
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_BRAKEY{0}", i)].ToString().Trim()), out VAX_VBRAKER[iPos]);       //右制动力

                    /////////////////20150422 VAX_VWGHTL  
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTFHZ{0}", i)].ToString().Trim()), out VAX_VWGHTL[iPos]);//左轮重复合台
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTFHY{0}", i)].ToString().Trim()), out VAX_VWGHTR[iPos]);//右轮重复合台
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_HALTZ{0}", i)].ToString().Trim()), out VAX_VPARKEL[iPos]);
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_HALTY{0}", i)].ToString().Trim()), out VAX_VPARKER[iPos]);
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTZ{0}", i)].ToString().Trim()), out VAX_VWGHTLSP[iPos]);//左轮重水平
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTY{0}", i)].ToString().Trim()), out VAX_VWGHTRSP[iPos]);//右轮重水平
                    //if (iVax > 2) //WWT 计算复合台轮重
                    //{
                    //}
                    if (VAX_WEIGHTZC[iPos] < 1)
                        VAX_WEIGHTZC[iPos] = VAX_VWGHTR[iPos] + VAX_VWGHTL[iPos];
                }

                for (int i = 0; i < 4; i++)
                {
                    float.TryParse(des.DeDES(dt.Rows[0][string.Format(@"DET_WEIGHTHJZ{0}", i+1)].ToString().Trim()), out VAX_WEIGHTZC[i]);  //轴重 lzj加载制动
                }

              
            }
        }
        public void getguangqiang(int zy,int yy)
        {
            int gqzh = 0;
            gqzh = zy + yy;
            string jielun = string.Format(@"{0},{1},{2},{3}",
                                "左右灯发光强度总和(cd)",
                                    gqzh,
                                    string.Format("≤{0}", 430000),
                                    gqzh < 430000 ? "合格" : "不合格");

            AddData(sDetectID, "PD_DGZH", "PD_AJ", jielun);

        }

        public void LedWrite(string lpUBuf, string lpDBuf, int iLedAdd)//灯牌显示
        {
            lpUBuf = getledstring(lpUBuf);
            lpDBuf = getledstring(lpDBuf);

            if (ledfactory.Contains("上海"))
            {
                int iph = 0;
                if (!int.TryParse(ledpinghao, out iph))
                {
                    iph = 1;
                }
                ledctrl.LedWriteSH(dpcomm, lpUBuf, lpDBuf, iph);
            }
            else if (ledfactory.Contains("深圳"))
            {
                int iph = 0;
                if (!int.TryParse(ledpinghao, out iph))
                {
                    iph = 3;
                }
                ledctrl.LedWriteSZ(dpcomm, lpUBuf, lpDBuf, iph);
            }
            else if (ledfactory.Contains("华燕"))
            {
                int iph = 0;
                if (!int.TryParse(ledpinghao, out iph))
                {
                    iph = 1;
                }
                ledctrl.LedWriteHY(dpcomm, lpUBuf, lpDBuf, iph);
            }
            else
            {
                ledctrl.LedWrite(dpcomm, lpUBuf, lpDBuf, iLedAdd);
            }
            writeled(lpUBuf, lpDBuf);
        }

        public void LedWritewkcc(string lpUBuf, string lpDBuf, int iLedAdd)//灯牌显示(专门用于外廓尺寸用于不同灯牌)
        {
            lpUBuf = getledstring(lpUBuf);
            lpDBuf = getledstring(lpDBuf);

            if (ledfactory.Contains("上海"))
            {
                ledctrl.LedWriteSH(dpcommwkcc, lpUBuf, lpDBuf, iLedAdd);
            }
            else if (ledfactory.Contains("深圳"))
            {
                int iph = 0;
                if (!int.TryParse(ledpinghao, out iph))
                {
                    iph = 3;
                }
                ledctrl.LedWriteSZ(dpcommwkcc, lpUBuf, lpDBuf, iph);
            }
            else if (ledfactory.Contains("华燕"))
            {
                int iph = 0;
                if (!int.TryParse(ledpinghao, out iph))
                {
                    iph = 1;
                }
                ledctrl.LedWriteHY(dpcommwkcc, lpUBuf, lpDBuf, iph);
            }
            else
            {
                ledctrl.LedWrite(dpcommwkcc, lpUBuf, lpDBuf, iLedAdd);
            }
        }
        public string getledstring(string sledstring)
        {
            byte[] ping = Encoding.GetEncoding("GB2312").GetBytes(sledstring);

            if (ping.Length > 16)
            {
                byte[] buf = new byte[16];
                for (int j = 0; j < 16; j++)
                {
                    buf[j] = ping[j];
                }
                sledstring = System.Text.Encoding.GetEncoding("GB2312").GetString(buf);
            }
            return sledstring;
        }
        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="detid">流水号</param>
        /// <param name="sziduan">字段名</param>
        /// <param name="sdatatable">数据表名</param>
        /// <param name="ssj">数据</param>
        /// <returns></returns>
        public bool AddData(string detid, string sziduan, string sdatatable, string ssj)
        {
            try
            {
                var sql = "";
               
                {
                    sql = string.Format(@"update {0} set {1}='{2}' where DETECT_ID={3} ",
                                              sdatatable, sziduan, ssj, detid);
                    m_mainform.objdbbass.InsertDB(sql);
                }
               
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddData_Check(string detid, string sziduan, string sdatatable, string ssj)
        {
             try
             {
                 var sql = "";
                 sql = string.Format(@"update {0} set {1}='{2}' where DETECT_ID={3}",sdatatable, sziduan, ssj, detid);
                 m_mainform.objdbbass.InsertDB(sql);
                 return true;
             }
             catch
             {
                 return false;
             }
               
        }
        

        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="detid">流水号</param>
        /// <param name="sziduan">字段名</param>
        /// <param name="sdatatable">数据表名</param>
        /// <param name="ssj">数据</param>
        /// <returns></returns>
        public bool AddData(string detid, string sziduan, string sdatatable, int ssj)
        {
            try
            {
                string sql = string.Format(@"update {0} set {1}={2} where DETECT_ID={3}",sdatatable, sziduan, ssj, detid);
                m_mainform.objdbbass.InsertDB(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="detid">流水号</param>
        /// <param name="sziduan">字段名</param>
        /// <param name="sdatatable">数据表名</param>
        /// <param name="ssj">数据</param>
        /// <returns></returns>
        public bool AddData(string detid, string sziduan, string sdatatable, float ssj)
        {
            try
            {
                string sql = string.Format(@"update {0} set {1}={2} where DETECT_ID={3}",sdatatable, sziduan, ssj, detid);
                m_mainform.objdbbass.InsertDB(sql);
                return true;
            }
            catch 
            {
                return false;
            }
        }

        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="detid">流水号</param>
        /// <param name="sziduan">字段名</param>
        /// <param name="sdatatable">数据表名</param>
        /// <param name="ssj">数据</param>
        /// <returns></returns>
      
        /// <summary>
        /// 执行sql
        /// </summary>
        /// <param name="detid">流水号</param>
        /// <param name="sziduan">字段名</param>
        /// <param name="sdatatable">数据表名</param>
        /// <param name="ssj">数据</param>
        /// <returns></returns>
        public bool AddData(string detid, string sziduan, string sdatatable, double ssj)//数据库，字段，赋值
        {
            try
            {
                string sql = string.Format(@"update {0} set {1}={2} where DETECT_ID={3}",sdatatable, sziduan, ssj, detid);
                m_mainform.objdbbass.InsertDB(sql);
                return true;
            }
            catch 
            {
                return false;
            }
        }

        public bool UpdateLoginRecord(string time, string wz, string detid)
        {
            try
            {
                string dqwz = "";
                string sql = string.Format(@"select DET_Location from Detects_SJA where DETECT_ID='{0}'", detid);
                DataTable dt = m_mainform.objdbbass.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    dqwz = dt.Rows[0]["DET_Location"].ToString().Trim();
                }
                if (!dqwz.Contains("检测线"))
                {
                    //保存数据
                    sql = string.Format(@"update Detects_SJA set DET_Location='{0}'where DETECT_ID={1} ", wz, detid);
                    m_mainform.objdbbass.InsertDB(sql);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        public void Updatejcxhao(string jcxhao, string detid)//flowbass.objcarclass
        {
            try
            {
                string sql = string.Format(@"update Detects_SJA set DET_JCXH='{0}'  where DETECT_ID='{1}'",jcxhao ,detid);
                m_mainform.objdbbass.InsertDB(sql);
            }
            catch
            {

            }
        }
      
        /// <summary>
        /// 曲线保存数据库
        /// </summary>
        /// <param name="detid"></param>
        /// <param name="sziduan"></param>
        /// <param name="sdatatable"></param>
        /// <param name="ssj"></param>
        /// <param name="ivax"></param>
        /// <returns></returns>
        public bool editData(string detid, string sziduan, string sdatatable, List<int> isz1, List<int> isz2)
        {
            try
            {
                byte[] bt = new byte[isz1.Count * 4];
                for (int i = 0; i < isz1.Count; i++)
                {
                    bt[i * 4 + 0] = ((byte)(isz1[i] % 256));
                    bt[i * 4 + 1] = ((byte)(isz1[i] / 256));
                    bt[i * 4 + 2] = ((byte)(isz2[i] % 256));
                    bt[i * 4 + 3] = ((byte)(isz2[i] / 256));
                }
                string sql = string.Format(@"update {0} set {1}=@vaxbrimage Where DETECT_ID={2}",
                                               sdatatable, sziduan, detid);
                m_mainform.InsertDBquxian(sql, bt);
                return true;
            }
            catch 
            {
                return false;
            }
        }


        /// <summary>
        /// 曲线保存数据库
        /// </summary>
        /// <param name="detid"></param>
        /// <param name="sziduan"></param>
        /// <param name="sdatatable"></param>
        /// <param name="ssj"></param>
        /// <param name="ivax"></param>
        /// <returns></returns>
        public bool editData(string detid, string sziduan, string sdatatable, List<double> isz1, List<double> isz2)
        {
            try
            {
                byte[] bt = new byte[isz1.Count * 4];
                for (int i = 0; i < isz1.Count; i++)
                {
                    bt[i * 4 + 0] = ((byte)(((int)isz1[i]) % 256));
                    bt[i * 4 + 1] = ((byte)(((int)isz1[i]) / 256));
                    bt[i * 4 + 2] = ((byte)(((int)isz2[i]) % 256));
                    bt[i * 4 + 3] = ((byte)(((int)isz2[i]) / 256));
                }

                string sql = string.Format(@"update {0} set {1}=@vaxbrimage Where DETECT_ID={2}",
                                               sdatatable, sziduan, detid);
                m_mainform.InsertDBquxian(sql, bt);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public int sendpiczj(string jkid, string tongdao, string gongwei, string zhidong)//抓拍指令
        {
            //return 0;
            //if ((sweburl + "").Length < 1)
            //{
            //    return 0;
            //}
//            jkid = "9999";

//            string sMessage = "<?xml version=\"1.0\" encoding=\"GBK\"?>" + string.Format(@"
//			<root>
//			<vehispara>
//			<jylsh>{0}</jylsh>
//			<jyjgbh>{1}</jyjgbh>
//			<hpzl>{2}</hpzl>
//			<hphm>{3}</hphm>
//			<tongdao>{4}</tongdao>
//			<gongwei>{5}</gongwei>
//			<xuhao>{6}</xuhao>
//			</vehispara>
//			</root>",
//                    jylsh,
//                    "",
//                    sPclass,
//                    sPlate,
//                    tongdao,
//                    gongwei,
//                    zhidong);
            model.安检联网.carclass objmodel=new model.安检联网.carclass();
            objmodel.hphm=sPlate;
            objmodel.hpzl = sPclass;
            objmodel.jcxdh = "";
            objmodel.jycs = "";
            objmodel.jyjgbh = "";
            objmodel.jylsh = jylsh;

            objajlwbass.sendpic(tongdao, gongwei, objmodel);//抓拍指令
            ////kssj 检验过程开始时间
           
            //WebReferenceAJ.Service objdata = new WebReferenceAJ.Service();
            //objdata.Url = sweburl;
            //string strfh = objdata.writeObjectOut("18", "", jkid, sMessage);
            return 0;
        }

      
        public string hphm = "";
        public string hpzl = "";
        public string jyjl = "合格";
        public bool sendAJendbak(string ID)
        {
            if (!ssfAJLW.Contains("是"))
            {
                return false;
            }
            //查询联网信息
            int zdjccs = 0;
            string zczdl = "";
            string zczdpd = "";
            string jcxdh = "";
            string jycs = "";
            string clsbdh = "";
            string sdpdt = "";//底盘动态判定
            string sdg = "";//底盘判定
            jyjl = "合格";
            WebReferenceAJ.Service m_sshenhe = new WebReferenceAJ.Service();
            m_sshenhe.Url = m_mainform.sweburl;




            var sql = "";
            sql = string.Format(@"SELECT * from AUTO,Detects_SJA,Detects_SJB where AUTO.AT_ID=Detects_SJA.AT_ID and Detects_SJB.DETECT_ID=Detects_SJA.DETECT_ID and Detects_SJA.DETECT_ID={0}", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                jcxdh = "1";//dt.Rows[0]["DET_JCXH"].ToString().Trim();
                jycs = dt.Rows[0]["DET_JYCS"].ToString().Trim();
                hpzl = dt.Rows[0]["AT_HPZL"].ToString().Trim();
                clsbdh = dt.Rows[0]["AT_VIN"].ToString().Trim();
                hphm = dt.Rows[0]["AT_HPHM"].ToString().Trim();
                zdjccs = Int32.Parse(dt.Rows[0]["DET_ZCCS"].ToString().Trim());
                zczdpd = dt.Rows[0]["DET_ZCJL"].ToString().Trim();
                sdpdt = dt.Rows[0]["DET_DYNAJL"].ToString().Trim();
                if ((sdpdt + "").Length < 1)
                {
                    sdpdt = "0";
                }
                sdg = dt.Rows[0]["DET_DCJL"].ToString().Trim();
                if ((sdg + "").Length < 1)
                {
                    sdg = "0";
                }

                zczdl = dt.Rows[0]["DET_BRAKEF"].ToString().Trim();

            }

            string vehispara18C82 = "";
            string stoubao18C82 = "<?xml version=\"1.0\" encoding=\"GBK\"?>";

            vehispara18C82 = stoubao18C82 + string.Format(@"<root><vehispara>
                            <jylsh>{0}</jylsh>
                            <jyjgbh>{1}</jyjgbh>
                            <jcxdh>{2}</jcxdh>
                            <hphm>{3}</hphm>
                            <hpzl>{4}</hpzl>
                            <clsbdh>{5}</clsbdh>
                            <ycyxm>{6}</ycyxm>
                            <ycysfzh>{7}</ycysfzh>
                             <zczdl>{8}</zczdl>
                             <zczdpd>{9}</zczdpd>
                             <zczdjyjg>{10}</zczdjyjg>
                             <zdjccs>{11}</zdjccs>
                            <zcpd>{12}</zcpd>
                            <zjccs>{13}</zjccs>
                            <jczczbzl>{14}</jczczbzl>
                            <bzzczbzl>{15}</bzzczbzl>
                            <zczbzlbfb>{16}</zczbzlbfb>
                            <zbzlpd>{17}</zbzlpd>
                            </vehispara></root>",
                       jylsh,
                       m_mainform.sjcz,
                       m_mainform.encode(jcxdh),
                        m_mainform.encode(hphm),
                        m_mainform.encode(hpzl.Substring(0, 2)),
                        m_mainform.encode(clsbdh),
                        sYCY,
                        "",
                        zczdl,//整车制动率
                        zczdpd,//整车制动判定
                        "0",//主车制动检验结果
                        zdjccs.ToString(),//整车制动次数
                        ok,//整车判定
                        m_mainform.encode(jycs),//总检验次数
                        "",//检验的整车整备质量
                        "",//标准的整车整备质量
                        "",//整车整备质量百分比
                        "");//整备质量判定

            string sjieguo18C82 = m_sshenhe.writeObjectOut("18", ssqm, "18C82", vehispara18C82);
            m_mainform.baocunriji(hphm + " " + "18C82", vehispara18C82);

            string vehispara18C59 = "";
            string stoubao18C59 = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehispara18C59 = stoubao18C59 + string.Format(@"<root><vehispara>
                            <jylsh>{0}</jylsh>
                            <jyjgbh>{1}</jyjgbh>
                            <jcxdh>{2}</jcxdh>
                            <jycs>{3}</jycs>
                            <hpzl>{4}</hpzl>
                            <hphm>{5}</hphm>
                            <clsbdh>{6}</clsbdh>
                            <jssj>{7}</jssj>
                            </vehispara></root>",
                jylsh,
                m_mainform.sjcz,
                m_mainform.encode(jcxdh),
                m_mainform.encode(jycs),
                m_mainform.encode(hpzl.Substring(0, 2)),
                 m_mainform.encode(hphm),
                m_mainform.encode(clsbdh),
                DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));


            string a = m_sshenhe.writeObjectOut("18", ssqm, "18C59", vehispara18C59);
            m_mainform.baocunriji(hphm + " " + "18C59", vehispara18C59);

            string rgjyjg = "";

            rgjyjg = string.Format(@"
        <rgjyjg><xh>1</xh><rgjyxm>{0}</rgjyxm><rgjgpd>1</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>2</xh><rgjyxm>{1}</rgjyxm><rgjgpd>1</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>3</xh><rgjyxm>{2}</rgjyxm><rgjgpd>1</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>4</xh><rgjyxm>{3}</rgjyxm><rgjgpd>1</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>5</xh><rgjyxm>{4}</rgjyxm><rgjgpd>1</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>6</xh><rgjyxm>{5}</rgjyxm><rgjgpd>{6}</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>
        <rgjyjg><xh>7</xh><rgjyxm>{7}</rgjyxm><rgjgpd>{8}</rgjgpd><rgjysm></rgjysm><rgjybz></rgjybz></rgjyjg>"
                , m_mainform.encode("车辆唯一性检查")
                , m_mainform.encode("车辆特征参数检查")
                , m_mainform.encode("车辆外观检查")
                , m_mainform.encode("安全装置检查")
                , m_mainform.encode("联网查询")
                , m_mainform.encode("底盘动态检验")
                , m_mainform.encode(sdpdt)
                , m_mainform.encode("车辆底盘部件检查")
                , m_mainform.encode(sdg));
            string yqsbjyjgs = "";
            if (m_iDetectID > 0)
            {
                string sqlPD = string.Format(@"Select * From PD_AJ Where DETECT_ID={0}", ID);
                string[] PDzd = { "PD_SPEED", "PD_WKCC", "PD_ZBZL", "PD_ZWDGQ", "PD_ZWDYGCZPYL", "PD_ZWDJGCZPYL", "PD_ZNDGQ", "PD_ZNDYGCZPYL", 
                                "PD_YWDGQ", "PD_YWDYGCZPYL", "PD_YWDJGCZPYL", "PD_YNDGQ", "PD_YNDYGCZPYL", "PD_LUSHI", "PD_KZCSD", "PD_KZZDJL", "PD_MZZDJL", 
                                "PD_KZMFDD", "PD_MZMFDD", "PD_XTSJ", "PD_BRIKE1", "PD_BRIKE2", "PD_BRIKE3", "PD_BRIKE4", "PD_BRIKE5", "PD_zhengche", "PD_ZHUCHE", "PD_JZBRLKE1",
                                "PD_JZBRLKE2","PD_JZBRLKE3","PD_JZBRLKE4","PD_ZWDYGSPPYL","PD_ZWDJGSPPYL","PD_ZNDYGSPPYL",
                                                    "PD_YWDYGSPPYL","PD_YWDJGSPPYL","PD_YNDYGSPPYL","PD_SLIP"};
                int ixh = 1;
                dt = m_mainform.objdbbass.GetTable(sqlPD);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < PDzd.Length; i++)
                    {

                        string spd = dt.Rows[0][PDzd[i]].ToString().Trim();
                        if (spd.Contains("不合格"))
                        {
                            jyjl = "不合格";
                        }
                        if (spd.Contains(","))
                        {
                            string[] sdatazs = spd.Split(new char[] { ',' });
                            string syqsb = string.Format(@"<yqsbjyjg><xh>{0}</xh><yqjyxm>{1}</yqjyxm><yqjyjg>{2}</yqjyjg><yqbzxz>{3}</yqbzxz><yqjgpd>{4}</yqjgpd><yqjybz></yqjybz></yqsbjyjg>", ixh, m_mainform.encode(sdatazs[0]), m_mainform.encode(sdatazs[1]), m_mainform.encode(sdatazs[2]), sdatazs[3].Contains("不合格") ? "2" : "1");
                            yqsbjyjgs = yqsbjyjgs + syqsb;
                            ixh++;
                        }
                    }
                }

            }
            yqsbjyjgs = yqsbjyjgs.Replace("(%)", "");

            //---------------------------------------------------
            //2.4.13.18C62-机动车检验判定结果信息
            string vehispara18C62 = "";
            string stoubao18C62 = "<?xml version=\"1.0\" encoding=\"GBK\"?>";
            vehispara18C62 = stoubao18C62 + string.Format(@"<root><vehispara>
                            <jylsh>{0}</jylsh>
                            <jyjgbh>{1}</jyjgbh>
                            <jcxdh>{2}</jcxdh>
                            <jycs>{3}</jycs>
                            <hphm>{4}</hphm>
                            <hpzl>{5}</hpzl>
                            <clsbdh>{6}</clsbdh>
                            <jyjl>{7}</jyjl>
                            <pzrxm>{8}</pzrxm>
                            <rgjyjgs>{9}</rgjyjgs>
                            <yqsbjyjgs>{10}</yqsbjyjgs>
                            <jybgjy>{11}</jybgjy>
                            <jybgbz>{12}</jybgbz>
                            </vehispara></root>",
                   jylsh,
                   m_mainform.sjcz,
                   jcxdh,
                   jycs,
                   m_mainform.encode(hphm),
                   m_mainform.encode(hpzl.Substring(0, 2)),
                   m_mainform.encode(clsbdh),
                   m_mainform.encode(jyjl),
                   m_mainform.encode(m_mainform.ssqqzr),//问题
                   rgjyjg,
                   yqsbjyjgs,
                   "",
                   "");
            string sjieguo = m_sshenhe.writeObjectOut("18", ssqm, "18C62", vehispara18C62);
            m_mainform.baocunriji(hphm + " " + "18C62", vehispara18C62);

            return true;
        }

        public string getbuhge(string ID,string bgxm)
        {
            string bhege = "";
            string sql = string.Format(@"select * from Detects_SJA where DETECT_ID='{0}'", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                bhege = dt.Rows[0]["DET_JYXM_Recheck"].ToString().Trim();
            }
            if (string.IsNullOrEmpty(bhege))
            {
                bhege = bgxm + ",";

            }
            else
            {
                if (!bhege.Contains(bgxm))
                {
                    bhege = bhege + bgxm + ",";
                }
            }
            AddData(ID, "DET_JYXM_Recheck", "Detects_SJA", bhege);
            return "";
        }

        public string sethege(string ID, string bgxm)
        {
            string bhege = "";
            string sql = string.Format(@"select * from Detects_SJA where DETECT_ID='{0}'", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                bhege = dt.Rows[0]["DET_JYXM_Recheck"].ToString().Trim();
                bhege = bhege.Replace(bgxm + ",", "");
                AddData(ID, "DET_JYXM_Recheck", "Detects_SJA", bhege);
            }
            //if ((bhege + "").Length > 1)
            //{
            //    if (!bhege.Contains(bgxm))
            //    {
            //        bhege = bhege + bgxm + ",";
            //    }
            //}
            //else
            //{
            //    bhege = bgxm + ",";
            //}
            //AddData(ID, "DET_JYXM_Recheck", "Detects_SJA", bhege);
            return "";
        }

        public string sethegezj(string ID)
        {
            string bhege = "";
            string sql = string.Format(@"select * from Detects_SJA where DETECT_ID='{0}'", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                bhege = dt.Rows[0]["DET_JYXM_Recheck"].ToString().Trim();
            }
            if (bhege.Trim().Length > 0)
            {
                AddData(ID, "DET_JYZJL", "Detects_SJA", "2");
            }
            else
            {
                AddData(ID, "DET_JYZJL", "Detects_SJA", "1");
            }
            return "";
        }
        public bool getfjxm(string ID, string bgxm)
        {
            string bhege = "";
            string sql = string.Format(@"select * from Detects_SJA where DETECT_ID='{0}'", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                bhege = dt.Rows[0]["DET_JYXM_Recheck"].ToString().Trim();
                if (bhege.Contains(bgxm))
                {
                    return true;
                }
            }
            return false;
        }
        //public void updatejl(string jl, string ID)
        //{
        //    if (jl.Trim().Length > 0)
        //    {
        //        string sql = string.Format(@"update Detects_SJA  set DET_JYZJL = '{0}'where DETECT_ID='{1}'", jl, ID);
        //        m_mainform.objdbbass.InsertDB(sql);
        //    }
        //    else
        //    {
        //        string sql = string.Format(@"select * from Detects_SJA where DETECT_ID='{0}'", ID);
        //        DataTable dt = m_mainform.objdbbass.GetTable(sql);
        //        if (dt.Rows.Count > 0)
        //        {
        //            jl = dt.Rows[0]["DET_JYZJL"].ToString().Trim();
        //        }
        //        if (jl.Trim().Length < 1)
        //        {
        //            sql = string.Format(@"update Detects_SJA  set DET_JYZJL =1 where DETECT_ID='{0}'", ID);
        //            m_mainform.objdbbass.InsertDB(sql);
        //        }
        //    }

        //}

        public void RecordProcessTime(int id, string shphm, string shpzl, string project, DateTime time, int number, string state)
        {

            string sql = "";
            sql = string.Format(@" select * from Table_ProcessTime where DETECT_ID={0} and TP_Number={1} and TP_Name='{2}'", id, number, project);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                if (state.Contains("开始"))
                {
                    sql = string.Format(@" update Table_ProcessTime set TP_StartTime='{0}' where DETECT_ID={1} and TP_Number={2} and TP_Name='{3}'",
                    time.ToString("yyyy-MM-dd HH:mm:ss"), id, number, project);
                }
                else
                {
                    StandardProcessTime(id, project, number, time);
                    if (!bStandard)
                    {
                        sql = string.Format(@" update Table_ProcessTime set TP_EndTime='{0}' where DETECT_ID={1} and TP_Number={2} and TP_Name='{3}'",
                            time.ToString("yyyy-MM-dd HH:mm:ss"), id, number, project);
                    }
                }

            }
            else
            {
                if (state.Contains("开始"))
                {
                    sql = string.Format(@" insert into Table_ProcessTime(
                                    DETECT_ID,TP_Hphm,TP_Hpzl,TP_Name,TP_StartTime,TP_Number)values(
                                    {0},
                                    '{1}',
                                    '{2}',
                                    '{3}',
                                     '{4}',
                                    '{5}')",
                                               id,
                                               shphm,
                                               shpzl,
                                               project,
                                               time.ToString("yyyy-MM-dd HH:mm:ss"),
                                               number);
                }
            }
            m_mainform.objdbbass.InsertDB(sql);
        }

        public  string suser = "";
        public void StandardProcessTime(int id, string project, int number, DateTime endtime)//调节达标视频时间
        {
            if (m_mainform.sfdbjcsj.Contains("否"))
            {
                return;
            }
            int timelimt = 60;
            string nowtime = "";
            string sql = "";
            string shphm = "";
            string shpzl = "";
            string scllx = "";
            suser = "";
            string timeunoperation = "";
            string timeother = "";
            string timemotor = "";
            


            sql = string.Format(@"select * from AUTO,Detects_SJA where AUTO.AT_ID=Detects_SJA.AT_ID and Detects_SJA.DETECT_ID={0}", id);
            DataTable dtsql = m_mainform.objdbbass.GetTable(sql);
            if (dtsql.Rows.Count > 0)
            {
                shphm = dtsql.Rows[0]["AT_HPHM"].ToString().Trim();
                shpzl = dtsql.Rows[0]["AT_HPZL"].ToString().Trim();
                scllx = dtsql.Rows[0]["AT_CLLX"].ToString().Trim();
                suser = dtsql.Rows[0]["AT_SYXZ"].ToString().Trim();
            }

            sql = string.Format(@"select * from Table_TimeLimit where TL_Name='{0}'", project);
            DataTable dtsqllimit = m_mainform.objdbbass.GetTable(sql);
            if (dtsqllimit.Rows.Count > 0)
            {
                timeunoperation = dtsqllimit.Rows[0]["TL_TimeUnOperation"].ToString().Trim();
                timeother = dtsqllimit.Rows[0]["TL_TimeOther"].ToString().Trim();
                timemotor = dtsqllimit.Rows[0]["TL_TimeMotor"].ToString().Trim();
            }
            //外观
            if (project.Contains("Appearance"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
                    {
                        int.TryParse(timeunoperation, out timelimt);//120
                    }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        int.TryParse(timemotor, out timelimt);//90
                    }
                    else
                    {
                        int.TryParse(timeother, out timelimt);//240
                    }
                }
            }
            //底盘动态
            if (project.Contains("Chassis"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
	                {
                        int.TryParse(timeunoperation, out timelimt);//60
	                }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        int.TryParse(timemotor, out timelimt);//90
                    }
                    else
                    {
                        int.TryParse(timeother, out timelimt);//60
                    }
                }
            }
            //底盘部件
            if (project.Contains("ChassisParts"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
                    {
                        int.TryParse(timeunoperation, out timelimt);//40
                    }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        int.TryParse(timemotor, out timelimt);//90
                    }
                    else
                    {
                        int.TryParse(timeother, out timelimt);//100
                    }
                }
            }
            //制动
            if (project.Contains("Braking"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
                    {
                        int.TryParse(timeunoperation, out timelimt);//40
                    }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        int.TryParse(timemotor, out timelimt);//30
                    }
                    else
                    {
                        int.TryParse(timeother, out timelimt);//60
                    }
                }
            }
            //灯光
            if (project.Contains("Lighting"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
                    {
                        int.TryParse(timeunoperation, out timelimt);//60
                    }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        int.TryParse(timemotor, out timelimt);//30
                    }
                    else
                    {
                        int.TryParse(timeunoperation, out timelimt);//60
                    }
                }
                timelimt = timelimt / 2;
            }
            //车速
            if (project.Contains("Speed"))
            {
                if (suser.Contains("非") && (scllx.Contains("客") || scllx.Contains("轿")))
                {
                    if (scllx.Contains("小") || scllx.Contains("微"))
                    {
                        timelimt = 0;
                    }
                }
                else
                {
                    if (scllx.Contains("摩托") || scllx.Contains("三轮"))
                    {
                        timelimt = 0;
                    }
                    else
                    {
                        int.TryParse(timeunoperation, out timelimt);//20
                    }
                }
            }



            DateTime jisuantime;
            sql = string.Format(@"select * from Table_ProcessTime where DETECT_ID={0} and TP_Name='{1}' and TP_Number={2}",
                id, project, number);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                nowtime = dt.Rows[0]["TP_StartTime"].ToString().Trim();
                jisuantime = DateTime.Parse(nowtime);
                for (; ; )
                {

                    //LedWrite("正在补全检测时间","",1);
                    //Thread.Sleep(100);//考虑是否补全

                    if (timelimt == 0)
                    {
                        bStandard = true;
                        break;
                    }
                    if (endtime > jisuantime.AddSeconds(timelimt))
                    {
                        bStandard = true;
                        break;
                    }
                    endtime = DateTime.Now;
                }

                sql = string.Format(@" update Table_ProcessTime set TP_EndTime='{0}' where DETECT_ID={1} and TP_Number={2} and TP_Name='{3}'",
                         endtime.ToString("yyyy-MM-dd HH:mm:ss"), id, number, project);
                m_mainform.objdbbass.InsertDB(sql);
            }

        }

        public bool LastProcessnew(int id)
        {
            bool zt = false;
            string[] xm;
            string[] xmfinish;
            string sSQLCmd = string.Format(@"SELECT * from dbo.AUTO,dbo.Detects_SJA where dbo.AUTO.AT_ID=Detects_SJA.AT_ID and Detects_SJA.DETECT_ID={0}", id);
            DataTable dt = m_mainform.objdbbass.GetTable(sSQLCmd);
            if (dt.Rows.Count > 0)
            {
                string sbjyxms = dt.Rows[0]["DET_BJYXM"].ToString().Trim();
                if (lwpt.Contains("睿擎"))
                {
                    sbjyxms = sbjyxms.Replace("F1,", "").Replace("DC,", "").Replace("DLX,", "").Replace("RYJJX,", "").Replace("XJ,", "").Replace("SJ,", "").Replace("ASM,", "").Replace("SDS,", "").Replace("ZYJS,", "").Replace("LUG,", "").Replace("R3,", "");
                }
                else
                {
                    sbjyxms = sbjyxms.Replace("DLX,", "").Replace("RYJJX,", "").Replace("XJ,", "").Replace("SJ,", "").Replace("ASM,", "").Replace("SDS,", "").Replace("ZYJS,", "").Replace("LUG,", "");
                }
                xm = sbjyxms.Split(',');
                //xm = dt.Rows[0]["DET_BJYXM"].ToString().Trim().Split(',');
                xmfinish = dt.Rows[0]["DET_EJYXM"].ToString().Trim().Split(',');
                var differ = xm.Where(c => !xmfinish.Contains(c)).ToArray();
                if (differ.Length > 0)
                {
                    zt = false;
                }
                else
                {
                    zt = true;
                }
            }
            return zt;
        }

        public string getProcessfinish(string ID, string bgxm)
        {
            string bhege = "";
            string sql = string.Format(@"select * from Detects_SJA where DETECT_ID={0}", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                bhege = dt.Rows[0]["DET_EJYXM"].ToString().Trim();
            }
            if ((bhege + "").Length > 1)
            {
                if (!bhege.Contains(bgxm))
                {
                    bhege = bhege + bgxm + ",";
                }
            }
            else
            {
                bhege = bgxm + ",";
            }
            AddData(ID, "DET_EJYXM", "Detects_SJA", bhege);
            return "";
        }

        public bool LastProcessnewzj(int id)
        {   
            bool zt = false;
            string[] xm;
            string[] xmfinish;
            string sSQLCmd = string.Format(@"SELECT * from dbo.AUTO,dbo.Detects_SJA where dbo.AUTO.AT_ID=Detects_SJA.AT_ID and Detects_SJA.DETECT_ID={0}", id);
            DataTable dt = m_mainform.objdbbass.GetTable(sSQLCmd);
            if (dt.Rows.Count > 0)
            {
                string sbjyxms = dt.Rows[0]["DET_BJYXM"].ToString().Trim();
                if (lwpt.Contains("睿擎"))
                {
                    sbjyxms = sbjyxms.Replace("F1,", "").Replace("DC,", "").Replace("C1,", "").Replace("ASM,", "").Replace("SDS,", "").Replace("ZYJS,", "").Replace("LUG,", "");
                }
                else
                {
                    sbjyxms = sbjyxms.Replace("ASM,", "").Replace("SDS,", "").Replace("ZYJS,", "").Replace("LUG,", "");
                }
                xm = sbjyxms.Split(',');
                xmfinish = dt.Rows[0]["DET_EJYXM"].ToString().Trim().Split(',');
                var differ = xm.Where(c => !xmfinish.Contains(c)).ToArray();
                if (differ.Length > 0)
                {
                    zt = false;
                }
                else
                {
                    zt = true;
                }
            }
            return zt;
        }

        public double DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            double dateDiff = 0;
            TimeSpan ts = DateTime1.Subtract(DateTime2).Duration();
            dateDiff = ts.Days * 60 * 60 * 60 * 1000 + ts.Hours * 60 * 60 * 1000 + ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
            return dateDiff;
        }

        public bool dlxsxpd(string ID)
        {
            string sql = string.Format(@"select DET_DLXJL from Detects_SJC where DETECT_ID={0}", ID);
            DataTable dt = m_mainform.objdbbass.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["DET_DLXJL"].ToString().Trim().Length > 0)
                {
                    return dt.Rows[0]["DET_DLXJL"].ToString().Trim().Contains("1") ? true : false;
                }
                else
                {
                    return false;
                }
            }
            return true;
        }

        public bool  cxjm(string hphm, string jyxm)
        {
            try
            {
                WebReferencejm.Service m_sshenhe = new WebReferencejm.Service();
                m_sshenhe.Url = m_mainform.web2;
                string message = m_sshenhe.Query(hphm, jyxm);
                if (message.Contains("<code>1</code>"))
                {
                    return true;
                }
            }
            catch (Exception ex) { }
            return false;
        }
        public int getycyzl(string sycy)
        {
            try
            {
                int iycyzl = 0;
                string ssql = string.Format("select * from USERE where NAME='{0}'", sycy);
                DataTable dt = m_mainform.objdbbass.GetTable(ssql);
                if (dt.Rows.Count > 0)
                {
                    string sycyzl = dt.Rows[0]["tizhong"].ToString().Trim();
                    int.TryParse(sycyzl, out iycyzl);
                }

                return iycyzl;

            }
            catch (Exception ex)
            {

            }
            return 75;
        }
        public string getycysfz(string sycy)
        {
                string sycyzl = "1";
            try
            {
                string ssql = string.Format("select * from USERE where NAME='{0}'", sycy);
                DataTable dt = m_mainform.objdbbass.GetTable(ssql);
                if (dt.Rows.Count > 0)
                {
                    sycyzl = dt.Rows[0]["SFZHM"].ToString().Trim();
                }
                if (sycyzl.Length < 1)
                    sycyzl = "1";
                return sycyzl;
            }
            catch (Exception ex)
            {
                return sycyzl;
            } 

        }
        public string getidname(string sid)
        {
            string sycyzl = "1";
            try
            {
                string ssql = string.Format("select * from USERE where YHLB='{0}'", sid);
                DataTable dt = m_mainform.objdbbass.GetTable(ssql);
                if (dt.Rows.Count > 0)
                {
                    sycyzl = dt.Rows[0]["NAME"].ToString().Trim();
                }
                if (sycyzl.Length < 1)
                    sycyzl = "1";
                return sycyzl;
            }
            catch (Exception ex)
            {
                return sycyzl;
            }

        }

        public void GetABS(string abs)
        {
            absType = "-";
            try
            {
                string sql = string.Format("select table_1 from table_ABS where table_2='{0}'", abs);
                DataTable dt = m_mainform.objdbbass.GetTable(sql);
                if (dt.Rows.Count > 0)
                {
                    absType = dt.Rows[0]["table_1"].ToString().Trim();
                }

            }
            catch (Exception ex)
            {

            }

        }

        public string getdpjyy(string sid)
        {
            string sycyzl = "";
            try
            {
                string ssql = string.Format("select DET_DPCZY from Detects_SJA where DETECT_ID='{0}'", sid);
                DataTable dt = m_mainform.objdbbass.GetTable(ssql);
                if (dt.Rows.Count > 0)
                {
                    sycyzl = dt.Rows[0]["DET_DPCZY"].ToString().Trim();
                }
                if (sycyzl.Length < 1)
                    sycyzl = "";
                return sycyzl;
            }
            catch (Exception ex)
            {
                return sycyzl;
            }

        }
        public void writeled(string sshang, string sxhang)
        {
            iniclass objini = new iniclass();
            string path = "";
            path = System.Windows.Forms.Application.StartupPath + path + "\\commled.ini";
            string path1 = string.Format(@"{0}", path);
            objini.Ini(path1);
            objini.Writue("数据", "上行", sshang);
            objini.Writue("数据", "下行", sxhang);

        }
    }
}
